var vm = new Vue({
    el: '#app',
    data: {
        host: host,
        error_username: false,
        error_pwd: false,
        error_pwd_message: '请填写密码',
        username:'',
        old_password: '',
        password: '',
        password2:'',
        remember: false,
        errmsg: '',
        errshow: false,
        error_opwd: false,
        error_pwd: false,
        error_cpwd: false,
    },




  
    methods: {
        // 获取url路径参数
        // 表单提交
        on_submit: function () {
            let token = localStorage.token;
            if (this.error_opwd == true || this.error_pwd == true || this.error_cpwd == true) {
                // 不满足修改密码条件：禁用表单
                window.event.returnValue = false;
                return;
            }
                    axios.post(this.host + '/re_password/',{
                        username :localStorage.username,
                        old_password:this.old_password,
                        password:this.password,
                        password2:this.password2,
                    },{
                        headers: {
                        'Authorization': 'JWT ' + token
                      },
                          responseType: 'json',
                          withCredentials:true,

                     })
                    .then(response=>{
                        if (response.data.code==0) {
                    
                        alert('修改成功')
                        location.href = 'login.html';
                        }
                    })
                    .catch(error=>{
                    if (error.response.code == 400) {
                        this.errmsg = '修改失败';
                        this.errshow = true;
                    }
                    }); 
        },

    }
});